const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const { ProvidePlugin } = require("webpack");
const webpack = require("webpack");
// webpack.config.js 文件

const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;

//--config ./config/common.config.js --env=development
// --config ./config/common.config.js --env=production

module.exports = {
  mode: "development",
  devtool: "source-map",
  devServer: {
    compress: true, //是否压缩
    open: true, //是否打开浏览器
    static: ["public"],
    // hot: "only",
    proxy: {
      "/api": {
        target: "http://localhost:3000", //静态资源和api服务在同一台服务器上
        pathRewrite: {
          "/api": "",
        }, //重写路径
      },
      changeOrigin: true,
    },

    historyApiFallback: true,
  },
  plugins: [
    //作用域提升，在生产环境自动生效
    new webpack.optimize.ModuleConcatenationPlugin(),
    new BundleAnalyzerPlugin(), // 使用默认配置
    // 默认配置的具体配置项
    // new BundleAnalyzerPlugin({
    //   analyzerMode: 'server',
    //   analyzerHost: '127.0.0.1',
    //   analyzerPort: '8888',
    //   reportFilename: 'report.html',
    //   defaultSizes: 'parsed',
    //   openAnalyzer: true,
    //   generateStatsFile: false,
    //   statsFilename: 'stats.json',
    //   statsOptions: null,
    //   excludeAssets: null,
    //   logLevel: info
    // })
  ],
};
